import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.*;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Vector;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FramePrincipal extends javax.swing.JFrame {

	private JMenuBar jMenuBar1;
	private JMenu jMenu1;
	private JMenu jMenu3;
	private JMenu jMenu4;
	private JMenu jMenu6;
	private JMenuItem Estudiante;
	private JMenuItem RProfesor;
	private JMenuItem AplicarEvaluaciones;
	private JRadioButtonMenuItem jRadioButtonOrdenarNot;
	private JMenuItem LGeneral;
	private JMenuItem LAprobados;
	private JMenuItem LAplazados;
	private JMenuItem Salir;
	private JMenuItem jMenuItem2;
	private JPopupMenu jPopupMenu1;
	private JRadioButtonMenuItem jRadioButtonOrdenarCed;
	private JMenu jMenu2;
	private JDesktopPane jDesktopPane1;
	private Image image;
	private Seccion sec;
	private int opc_ordenar = 0;

	ActionListener opc_ced = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			opc_ordenar = 0;
		}
    };
    ActionListener opc_nota = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			opc_ordenar = 1;
		}
    };
    ActionListener rep_general = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			String t = "Listado General ordenado por " + Ordenar();
			Reporte(sec.getEstudiantes(),t);
		}
    };
    ActionListener rep_aprob = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			String t = "Listado de Aprobados ordenado por " + Ordenar();
			Reporte(sec.getEstudiantesAprob(),t);
		}
    };
    ActionListener rep_aplaz = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			String t = "Listado de Aplazados ordenado por " + Ordenar();
			Reporte(sec.getEstudiantesAplaz(),t);
		}
    };
    public String Ordenar()
    {
    	if(opc_ordenar == 0)
    	{
			this.sec.OrdenarEstudianteCed();
    	    return "Cedula";
    	}
    	else
    	{
    		this.sec.OrdenarEstudianteNota();
    		return "Nota Final";
    	}
    }
    public void Reporte(Vector<Estudiante> Est,String t)
    {
    	if(this.sec.NumeroEstudiante() == 0)
    		JOptionPane.showMessageDialog(null,"No Existen estudiantes registrados", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
    	else if(Est.size() != 0)
    	{
	    	JFrame frame = new JFrame();
			JTableDemo inst = new JTableDemo(Est,t);
			frame.getContentPane().add(inst);
			((JComponent)frame.getContentPane()).setPreferredSize(inst.getSize());
			frame.pack();
			frame.setVisible(true);
			frame.setTitle(t);
			frame.setLocationRelativeTo(null);
			inst.setSize(new Dimension(600, 300));
    	}
    	else
    		JOptionPane.showMessageDialog(null,"No Existen estudiantes que cumplan la condicion", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
    }
	
	
	ActionListener Ventprof = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			FrameProfesor ventProf = new FrameProfesor(sec);
			ventProf.setVisible(true);
			ventProf.setLocationRelativeTo(null);
		}
    };
    ActionListener VentEst = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			FrameEstudiante ventEstud = new FrameEstudiante(sec);
			ventEstud.setVisible(true);
			ventEstud.setLocationRelativeTo(null);
		}
    };
    
    ActionListener Evaluar = new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			AplicarEvaluacion();
		}
    };
    
    public void AplicarEvaluacion()
    {
        if(this.sec.NumeroEstudiante() == 0)
        	JOptionPane.showMessageDialog(null,"No Existen estudiantes registrados", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        else if(!this.sec.getProfReg())
        	JOptionPane.showMessageDialog(null,"No Existe profesor registrado", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
        else
        {
        	this.sec.AplicarEvaluaciones();
        	this.sec.EvaluarEstuduantes();
        	JOptionPane.showMessageDialog(null,"La evaluacion fue realizada con exito", "Operación Realizada", JOptionPane.INFORMATION_MESSAGE);
    	}
    }
	
	public FramePrincipal() {
		super();
		initGUI();
		Panel pan = new Panel("/Imagenes/imagen2.jpg", this.getWidth(), this.getHeight());
		this.add(pan, BorderLayout.CENTER);
		pan.setPreferredSize(new java.awt.Dimension(486, 273));
	}
	public FramePrincipal(Seccion sec) {
		super();
		this.sec = sec;
		initGUI();
		this.setTitle("Registro Academico (Seccion " + this.sec.getNum_secc() + ")");
		Panel pan = new Panel("/Imagenes/imagen2.jpg", this.getWidth(), this.getHeight());
		this.add(pan, BorderLayout.CENTER);
		pan.setPreferredSize(new java.awt.Dimension(486, 273));
	}
	
	private void initGUI() {
		try {
			{
				this.setFont(new java.awt.Font("DejaVu Sans Mono",0,10));
				getContentPane().setForeground(new java.awt.Color(255,255,255));
				this.setJMenuBar(jMenuBar1);
			}
			{
				this.setJMenuBar(jMenuBar1);
			}
			{
				jDesktopPane1 = new JDesktopPane();
				getContentPane().add(jDesktopPane1, BorderLayout.CENTER);
				jDesktopPane1.setPreferredSize(new java.awt.Dimension(390, 159));
				{
					jPopupMenu1 = new JPopupMenu();
					setComponentPopupMenu(jDesktopPane1, jPopupMenu1);
				}
				{
					jMenuItem2 = new JMenuItem();
					jDesktopPane1.add(jMenuItem2, JLayeredPane.DEFAULT_LAYER);
					jMenuItem2.setText("jMenuItem2");
				}
			}
			this.setSize(598, 433);
			{
				jMenuBar1 = new JMenuBar();
				setJMenuBar(jMenuBar1);
				{
					jMenu1 = new JMenu();
					jMenuBar1.add(jMenu1);
					jMenu1.setText("Registrar");
					{
						Estudiante = new JMenuItem();
						jMenu1.add(Estudiante);
						Estudiante.setText("Estudiante");
						Estudiante.addActionListener(VentEst);						
					}
					{
						RProfesor = new JMenuItem();
						jMenu1.add(RProfesor);
						RProfesor.setText("Profesor");
						RProfesor.addActionListener(Ventprof);
					}
				}
				{
					jMenu4 = new JMenu();
					jMenuBar1.add(jMenu4);
					jMenu4.setText("Evaluar");
					{
						AplicarEvaluaciones = new JMenuItem();
						jMenu4.add(AplicarEvaluaciones);
						AplicarEvaluaciones.addActionListener(Evaluar);
						AplicarEvaluaciones.setText("Aplicar Evaluaciones");
					}

				}
				{
					jMenu3 = new JMenu();
					jMenu3.setText("Reportes");
					jMenuBar1.add(jMenu3);
					{
						jMenu4 = new JMenu();
						jMenu4.setText("Estudiantes");
						jMenu3.add(jMenu4);
						{
							LGeneral = new JMenuItem();
							jMenu4.add(LGeneral);
							LGeneral.setText("General");
							LGeneral.addActionListener(rep_general);
						}
						{
							LAprobados = new JMenuItem();
							jMenu4.add(LAprobados);
							LAprobados.setText("Aprobados");
							LAprobados.addActionListener(rep_aprob);
						}
						{
							LAplazados = new JMenuItem();
							jMenu4.add(LAplazados);
							LAplazados.setText("Aplazados");
							LAplazados.addActionListener(rep_aplaz);
						}
						{
							jMenu2 = new JMenu();
							jMenu4.add(jMenu2);
							jMenu2.setText("Ordenar Por");
							{
								jRadioButtonOrdenarCed = new JRadioButtonMenuItem();
								jMenu2.add(jRadioButtonOrdenarCed);
								jRadioButtonOrdenarCed.setText("Cedula");
							}
							{
								jRadioButtonOrdenarNot = new JRadioButtonMenuItem();
								jMenu2.add(jRadioButtonOrdenarNot);
								jRadioButtonOrdenarNot.setText("Nota Final");
							}
						}
					}
				}
				{
					jMenu6 = new JMenu();
					jMenuBar1.add(jMenu6);
					jMenu6.setText("Salir");
					jRadioButtonOrdenarCed.addActionListener(opc_ced);
                    jRadioButtonOrdenarNot.addActionListener(opc_nota);
					{
						JMenuItem Salir = new JMenuItem("Salir");
						jMenu6.add(Salir);
					    Salir.addActionListener(
				        new ActionListener() 
				        { 
					      public void actionPerformed( ActionEvent evento )
					      {
					         System.exit( 0 );
					      }
					    } 

					); 
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	* Auto-generated method for setting the popup menu for a component
	*/
	private void setComponentPopupMenu(final java.awt.Component parent, final javax.swing.JPopupMenu menu) {
		parent.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mousePressed(java.awt.event.MouseEvent e) {
				if(e.isPopupTrigger())
					menu.show(parent, e.getX(), e.getY());
			}
			public void mouseReleased(java.awt.event.MouseEvent e) {
				if(e.isPopupTrigger())
					menu.show(parent, e.getX(), e.getY());
			}
		});
	}

}
